package com.dirk.happie.adapters;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.dirk.happie.R;
import com.dirk.happie.beans.AddressBean;

public class AddressListAdapter extends ArrayAdapter<AddressBean> {

	int layoutResourceId;
	private LayoutInflater inflater = null;

	public AddressListAdapter(Context context, int layoutResourceId, ArrayList<AddressBean> data) {
		super(context, layoutResourceId, data);
		this.layoutResourceId = layoutResourceId;
		inflater = ((Activity) context).getLayoutInflater();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		ProductTypeHolder holder = null;

		if (row == null) {

			row = inflater.inflate(layoutResourceId, parent, false);

			holder = new ProductTypeHolder();
			holder.txtAddress = (TextView) row.findViewById(R.id.txtAddress);

			row.setTag(holder);
		} else {
			holder = (ProductTypeHolder) row.getTag();
		}

		holder.txtAddress.setText(getItem(position).getCity() + ", " + getItem(position).getStreet() + ", " + getItem(position).getApt() + ", " + getItem(position).getZip());

		return row;
	}

	static class ProductTypeHolder {
		TextView txtAddress;

	}
}
